package servicesImp.dictionary;


import base.IBaseMapperWithoutBLOBs;
import base.IBaseServicesWithoutBLOBsImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import services.dictionary.ManagerAssessTypeServices;
import wt.dao.dictionary.ManagerAssessTypeMapper;
import wt.entity.dictionary.ManagerAssessType;
import wt.entity.dictionary.ManagerAssessTypeExample;
import wt.staticData.TableName;

import java.util.List;

/**
 * Created by Administrator on 2017/10/14.
 */
@Service
public class ManagerAssessTypeServicesImp extends IBaseServicesWithoutBLOBsImpl<ManagerAssessType,ManagerAssessTypeExample> implements ManagerAssessTypeServices {
    @Autowired
    ManagerAssessTypeMapper managerAssessTypeMapper;

    @Override
    public IBaseMapperWithoutBLOBs< ManagerAssessType, ManagerAssessTypeExample> getMapper() {
        return this.managerAssessTypeMapper;
    }

    @Override
    public String getTableName() {
        return TableName.DIC_MANAGER_ASSESS_TYPE;
    }




    public List<ManagerAssessType> selectManagerAssessType(String itemId, boolean isOnlyLive) throws Exception {

        ManagerAssessTypeExample managerAssessTypeExample = new ManagerAssessTypeExample();
        managerAssessTypeExample.setOrderByClause("num");
        if (itemId == null) {
            if (isOnlyLive == true) {
                managerAssessTypeExample.createCriteria().andLiveEqualTo((short) 1);
            }
        } else {
            if (isOnlyLive == true) {
                managerAssessTypeExample.createCriteria().andItemIdEqualTo(itemId).andLiveEqualTo((short) 1);

            } else {
                managerAssessTypeExample.createCriteria().andItemIdEqualTo(itemId);
            }
        }
        return selectByExample(managerAssessTypeExample);
    }


    @Transactional
    public void updateManagerAssessTypeLive(List<String> setLiveIdList, List<String> setNoLiveIdList) throws Exception {
        ManagerAssessType managerAssessType = new ManagerAssessType();
        managerAssessType.setLive((short) 1);
        for (int i = 0; setLiveIdList != null && i < setLiveIdList.size(); i = i + 1000) {
            ManagerAssessTypeExample managerAssessTypeExample = new ManagerAssessTypeExample();
            managerAssessTypeExample.createCriteria().andIdIn(setLiveIdList.subList(i,setLiveIdList.size()-i>=1000?i+1000:setLiveIdList.size()));
            getCurrentProxy().updateByExampleSelective(managerAssessType, managerAssessTypeExample);
        }


        managerAssessType.setLive((short) 0);
        for (int i = 0; setNoLiveIdList != null && i < setNoLiveIdList.size(); i = i + 1000) {
            ManagerAssessTypeExample managerAssessTypeExample = new ManagerAssessTypeExample();
            managerAssessTypeExample.createCriteria().andIdIn(setNoLiveIdList.subList(i,setNoLiveIdList.size()-i>=1000?i+1000:setNoLiveIdList.size()));
            getCurrentProxy().updateByExampleSelective(managerAssessType, managerAssessTypeExample);
        }
    }

    public List<ManagerAssessType> selectTreeByLeafIds(List<String> leafIdList) {


//        if (leafIdList==null || leafIdList.size()==0){
//            return new ArrayList<ManagerAssessType>();
//        }
//        return managerAssessTypeMapper.selectTreeByLeafId(leafIdList);

        throw  new RuntimeException("方法未实现");
    }
    
    
}
